﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CooWork.Models;
using Coowork.Data.Mapping;

namespace CooWork.Services
{
    public class Message:IMessage
    {

        public void SendMessage(string msg, List<System.Guid> ulist)
        {
            CooWorkEntities ctx = new CooWorkEntities();

            CooMessage cm = new CooMessage();
            cm.Body = msg;
            cm.CreateTime = DateTime.Now;            
            foreach (Guid g in ulist)
            {
                CooMessageOp cmo=new CooMessageOp();
                cmo.Muser = g;
                cmo.Mstatus = 1;
                cm.CooMessageOps.Add(cmo);
                //ctx.CooMessageOps.Add
            }

            ctx.CooMessages.Add(cm);
            ctx.SaveChanges();
        }

    }
}